<template>
	<div class="search-container">
		<el-form ref="searchRef" :model="query" :inline="true">
			<el-form-item :label="item.label" :prop="item.prop" v-for="item in options">
				<!-- 文本框、下拉框、日期框 -->
				<el-input v-if="item.type === 'input'" v-model="query[item.prop]" :disabled="item.disabled"
					:placeholder="item.placeholder" clearable></el-input>
				<el-select v-else-if="item.type === 'select'" v-model="query[item.prop]" :disabled="item.disabled"
					:placeholder="item.placeholder" clearable>
					<el-option v-for="opt in item.opts" :label="opt.label" :value="opt.value"></el-option>
				</el-select>
				<el-date-picker v-else-if="item.type === 'date'" type="date" v-model="query[item.prop]"
					:value-format="item.format"></el-date-picker>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" :icon="Search" @click="search">查找设备</el-button>
        <el-button type="primary"  @click="searchoverdue">查找逾期设备</el-button>
        <el-button type="primary"  @click="searchwilloverdue">查找即将逾期设备</el-button>
        <el-button type="info"  @click="exportByCompanyName">导出</el-button>
				<el-button :icon="Refresh" @click="reset">重置</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script lang="ts" setup>
import { FormInstance } from 'element-plus';
import { Search, Refresh } from '@element-plus/icons-vue';
import { PropType, ref } from 'vue';
import { FormOptionList } from '@/types/form-option';

const props = defineProps({
	query: {
		type: Object,
		required: true
	},
	options: {
		type: Array as PropType<Array<FormOptionList>>,
		required: true
	},
	search: {
		type: Function,
		default: () => { }
	},
  searchoverdue: {
    type: Function,
    default: () => { }
  },
  searchwilloverdue: {
    type: Function,
    default: () => { }
  },
  exportByCompanyName: {
    type: Function,
    default: () => { }
  }
});
const emit = defineEmits(['reset']);
const searchRef = ref<FormInstance>();

const searchoverdue = () => {
  props.searchoverdue(); // 调用父组件传递的 searchoverdue 函数
};

const searchwilloverdue = () => {
  props.searchwilloverdue(); // 调用父组件传递的 searchwilloverdue 函数
};

const exportByCompanyName = () => {
  props.exportByCompanyName(); // 调用父组件传递的 searchwilloverdue 函数
};

const reset = () => {
  if (searchRef.value) {
    searchRef.value.resetFields(); // 清空表单
  }
  emit('reset'); // 触发父组件的重置逻辑
};
</script>

<style scoped>
.search-container {
	padding: 20px 30px 0;
	background-color: #fff;
	margin-bottom: 10px;
	border: 1px solid #ddd;
	border-radius: 5px
}
</style>
